package cn.youth996.nav.service.impl;

import cn.youth996.nav.domain.GeoPointPic;
import cn.youth996.nav.mapper.GeoPointPicMapper;
import cn.youth996.nav.service.GeoPointPicService;
import cn.youth996.nav.util.PageUtils;
import cn.youth996.nav.util.Query;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 地理坐标图片信息
 *
 * @author Zhan Xinjian
 * @date 2025/7/10
 */
@Service
public class GeoPointPicServiceImpl extends ServiceImpl<GeoPointPicMapper, GeoPointPic>
    implements GeoPointPicService{
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        // 构建查询条件包装器
        QueryWrapper<GeoPointPic> wrapper = this.getWrapper(params);

        // 执行分页查询
        IPage<GeoPointPic> page = this.page(
                new Query<GeoPointPic>().getPage(params),
                wrapper
        );

        // 返回封装好的分页结果
        return new PageUtils(page);
    }


    @Override
    public List<GeoPointPic> list(Map<String, Object> params) {
        // 构建查询条件包装器
        QueryWrapper<GeoPointPic> wrapper = this.getWrapper(params);
        // 使用MyBatis-Plus提供的方法进行查询，并返回查询结果
        return baseMapper.selectList(wrapper);
    }

    @Override
    public List<GeoPointPic> listByPointId(Long pointId) {
        QueryWrapper<GeoPointPic> wrapper = new QueryWrapper<>();
        wrapper.eq( "point_id", pointId);
        return baseMapper.selectList(wrapper);
    }

    public QueryWrapper<GeoPointPic> getWrapper(Map<String, Object> params) {
        // 从参数映射表中获取设备代码
        String id = (String) params.get("id");
        // 创建一个QueryWrapper对象，用于构建查询条件
        QueryWrapper<GeoPointPic> wrapper = new QueryWrapper<>();
        wrapper.eq(StringUtils.isNotBlank(id), "id", id);
        return wrapper;
    }
}




